//
//  Extension+Asset.swift
//  TCMHealth
//
//  Created by 韩颖 on 2023/7/2.
//

import Foundation
import Photos
extension PHAsset {
    func getVideoUrl(complete:@escaping (_ url:String?)->()){
        let options: PHVideoRequestOptions = PHVideoRequestOptions()
        options.version = .original
        
        PHImageManager.default().requestAVAsset(forVideo: self, options: options, resultHandler: {(asset: AVAsset?, audioMix: AVAudioMix?, info: [AnyHashable : Any]?) -> Void in
            if let urlAsset = asset as? AVURLAsset {
                let localVideoUrl: URL = urlAsset.url as URL
                complete(localVideoUrl.path)
            } else {
                complete(nil)
            }
        })
    }
}
